package clientapp;

import java.util.Calendar;
import java.util.GregorianCalendar;
import serverapp.Player;

/**
 *
 * @author Master
 */
public class addPlayerFrame extends javax.swing.JFrame {

    
    Player player;
    Player player_new;
    playerPanel newPanel;
    
    /** Creates new form addPlayerFrame */
    public addPlayerFrame() {
        initComponents();
    }
    
    public addPlayerFrame(Player player) {
        initComponents();
    
        this.player = player;
        
        String name = player.name;
        String surname = player.surname;
        String nationality = player.nationality;
        String age = Integer.toString(player.age);
        String club = player.club;
        String position = player.position;
        String height = Integer.toString(player.height);
        String weight = Integer.toString(player.weight);
        String attRange = Integer.toString(player.attRange);
        String defRange = Integer.toString(player.defRange);
        
        this.player_new = new Player();
        this.newPanel = new playerPanel(this.player_new);
        Calendar calendar = GregorianCalendar.getInstance();
        String date = calendar.getTime().toString();
        newPanel.nameLabel.setText(name);
        newPanel.surnameLabel.setText(surname);
        newPanel.nationalityLabel.setText(nationality);
        newPanel.ageLabel.setText(age);
        newPanel.clubLabel.setText(club);
        newPanel.positionLabel.setText(position);
        newPanel.heightLabel.setText(height);
        newPanel.weightLabel.setText(weight);
        newPanel.attRangeLabel.setText(attRange);
        newPanel.defRangeLabel.setText(defRange);
        newPanel.dateLabel.setText(date);
        ClientView.tabbedPane.addTab(name + surname, newPanel);
        this.setVisible(false);
    
    }
    
    public void updatePlayerStats() {
        this.player.blockedAttacks = this.player.blockedAttacks + this.player_new.blockedAttacks;
        this.player.successAttacks = this.player.successAttacks + this.player_new.successAttacks;
        this.player.failedAttacks = this.player.failedAttacks + this.player_new.failedAttacks;
        this.player.successBlocks = this.player.successBlocks + this.player_new.successBlocks;
        this.player.defendedBlocks = this.player.defendedBlocks + this.player_new.defendedBlocks;
        this.player.defendedBlocks = this.player.defendedBlocks + this.player_new.defendedBlocks;
        this.player.failedBlocks = this.player.failedBlocks + this.player_new.failedBlocks;
        this.player.serveAces = this.player.serveAces + this.player_new.serveAces;
        this.player.receivedServes = this.player.receivedServes + this.player_new.receivedServes;
        this.player.failedServes = this.player.failedServes + this.player_new.failedServes;
        this.player.receivesToNet = this.player.receivesToNet + this.player_new.receivesToNet;
        this.player.bouncedReceives = this.player.bouncedReceives + this.player_new.bouncedReceives;
        this.player.failedReceives = this.player.failedReceives + this.player_new.failedReceives;
        this.player.defencesNet = this.player.defencesNet + this.player_new.defencesNet;
        this.player.bouncedDefences = this.player.bouncedDefences + this.player_new.bouncedDefences;
        this.player.failedDefences = this.player.failedDefences + this.player_new.failedDefences;
        this.player.singleBlockPasses = this.player.singleBlockPasses + this.player_new.singleBlockPasses;
        this.player.tripleBlockPasses = this.player.tripleBlockPasses + this.player_new.tripleBlockPasses;
        this.player.failedPasses = this.player.failedPasses + this.player_new.failedPasses;
//        player. = player. + newPanel.;
    }
    
    // Zwraca najblizszy indeks wolnego panelu (NIE UZYWANE)
    public int nextFreePanel(boolean Table[]) {
        int result = -1;
        for (int i = 0; i < Table.length; i++) {
            if (Table[i] == false) {
                result = i;
                break;
            }
        }
        return result;
    }
    /* Aktualnie nie uzywana, ale nie usuwac! */

    public void openNewPanel(playerPanel elo, String name, String surname, String nationality, String age,
            String club, String position, String height, String weight, String attRange, String defRange, String panelNumber) {

      //  playerPanel newPanel = new playerPanel();
        Calendar calendar = GregorianCalendar.getInstance();
        String date = calendar.getTime().toString();
        newPanel.nameLabel.setText(name);
        newPanel.surnameLabel.setText(surname);
        newPanel.nationalityLabel.setText(nationality);
        newPanel.ageLabel.setText(age);
        newPanel.clubLabel.setText(club);
        newPanel.positionLabel.setText(position);
        newPanel.heightLabel.setText(height);
        newPanel.weightLabel.setText(weight);
        newPanel.attRangeLabel.setText(attRange);
        newPanel.defRangeLabel.setText(defRange);
        newPanel.dateLabel.setText(date);
        ClientView.tabbedPane.addTab(panelNumber, newPanel);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {


        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        nameField = new javax.swing.JTextField();
        surnameField = new javax.swing.JTextField();
        nationalityField = new javax.swing.JTextField();
        ageField = new javax.swing.JTextField();
        clubField = new javax.swing.JTextField();
        addButton = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        heightField = new javax.swing.JTextField();
        positionField = new javax.swing.JTextField();
        weightField = new javax.swing.JTextField();
        attRangeField = new javax.swing.JTextField();
        defRangeField = new javax.swing.JTextField();


        setName("Form"); // NOI18N


        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(clientapp.ClientApp.class).getContext().getResourceMap(addPlayerFrame.class);
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N


        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N


        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N


        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N


        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N


        nameField.setText(resourceMap.getString("nameField.text")); // NOI18N
        nameField.setName("nameField"); // NOI18N


        surnameField.setText(resourceMap.getString("surnameField.text")); // NOI18N
        surnameField.setName("surnameField"); // NOI18N


        nationalityField.setText(resourceMap.getString("nationalityField.text")); // NOI18N
        nationalityField.setName("nationalityField"); // NOI18N


        ageField.setText(resourceMap.getString("ageField.text")); // NOI18N
        ageField.setName("ageField"); // NOI18N


        clubField.setText(resourceMap.getString("clubField.text")); // NOI18N
        clubField.setName("clubField"); // NOI18N


        addButton.setText(resourceMap.getString("addButton.text")); // NOI18N
        addButton.setName("addButton"); // NOI18N
        addButton.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addButtonActionPerformed(evt);
            }
        });


        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N


        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N


        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N


        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N


        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N


        heightField.setText(resourceMap.getString("heightField.text")); // NOI18N
        heightField.setName("heightField"); // NOI18N


        positionField.setText(resourceMap.getString("positionField.text")); // NOI18N
        positionField.setName("positionField"); // NOI18N


        weightField.setText(resourceMap.getString("weightField.text")); // NOI18N
        weightField.setName("weightField"); // NOI18N


        attRangeField.setText(resourceMap.getString("attRangeField.text")); // NOI18N
        attRangeField.setName("attRangeField"); // NOI18N


        defRangeField.setText(resourceMap.getString("defRangeField.text")); // NOI18N
        defRangeField.setName("defRangeField"); // NOI18N


        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jLabel1).addComponent(jLabel2)).addGap(26, 26, 26).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING).addComponent(surnameField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 71, Short.MAX_VALUE).addComponent(nameField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 71, Short.MAX_VALUE))).addGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jLabel3).addComponent(jLabel4).addComponent(jLabel5)).addGap(18, 18, 18).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(nationalityField, javax.swing.GroupLayout.DEFAULT_SIZE, 70, Short.MAX_VALUE).addComponent(ageField, javax.swing.GroupLayout.DEFAULT_SIZE, 70, Short.MAX_VALUE).addComponent(clubField, javax.swing.GroupLayout.DEFAULT_SIZE, 70, Short.MAX_VALUE)))).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jLabel9).addComponent(jLabel10).addComponent(jLabel6).addComponent(jLabel7).addComponent(jLabel8)).addGap(18, 18, 18).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false).addComponent(weightField, javax.swing.GroupLayout.Alignment.TRAILING).addComponent(heightField, javax.swing.GroupLayout.Alignment.TRAILING).addComponent(defRangeField).addComponent(attRangeField).addComponent(positionField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)).addGap(22, 22, 22)).addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addComponent(addButton).addContainerGap()))));
        layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel1).addComponent(nameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(jLabel6).addComponent(positionField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel2).addComponent(surnameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(jLabel7).addComponent(heightField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel3).addComponent(nationalityField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(weightField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(jLabel8)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel4).addComponent(ageField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(jLabel9).addComponent(attRangeField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel5).addComponent(clubField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(jLabel10).addComponent(defRangeField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 31, Short.MAX_VALUE).addComponent(addButton).addContainerGap()));


        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonActionPerformed
        String name = nameField.getText();
        String surname = surnameField.getText();
        String nationality = nationalityField.getText();
        String age = ageField.getText();
        String club = clubField.getText();
        String position = positionField.getText();
        String height = heightField.getText();
        String weight = weightField.getText();
        String attRange = attRangeField.getText();
        String defRange = defRangeField.getText();

//        playerPanel newPanel = new playerPanel();
        Calendar calendar = GregorianCalendar.getInstance();
        String date = calendar.getTime().toString();
 /*       newPanel.nameLabel.setText(name);
        newPanel.surnameLabel.setText(surname);
        newPanel.nationalityLabel.setText(nationality);
        newPanel.ageLabel.setText(age);
        newPanel.clubLabel.setText(club);
        newPanel.positionLabel.setText(position);
        newPanel.heightLabel.setText(height);
        newPanel.weightLabel.setText(weight);
        newPanel.attRangeLabel.setText(attRange);
        newPanel.defRangeLabel.setText(defRange);
        newPanel.dateLabel.setText(date); */
        ClientView.tabbedPane.addTab(name + surname, newPanel);
        this.setVisible(false);
    }//GEN-LAST:event_addButtonActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new addPlayerFrame().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addButton;
    private javax.swing.JTextField ageField;
    public static javax.swing.JTextField attRangeField;
    private javax.swing.JTextField clubField;
    public static javax.swing.JTextField defRangeField;
    public static javax.swing.JTextField heightField;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JTextField nameField;
    private javax.swing.JTextField nationalityField;
    public static javax.swing.JTextField positionField;
    private javax.swing.JTextField surnameField;
    public static javax.swing.JTextField weightField;
    // End of variables declaration//GEN-END:variables
}